import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, SelectButton } from '../Common/options'
import { ProjectList, DataSynchronization } from '../Common/Conversion'
const { hostname } = window.location

export const Helmet = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const centNameOptions = await DataSynchronization()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === '3aa93a0f-5bb0-46f6-862a-a05fca37f778') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增安全帽信息" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            {
                dataIndex: 'tableName',
                title: '人员姓名',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'organizationUuid',
                title: '组织机构',
                rules: true,
                valueType: 'select',
                valueEnum: ClientData.organization,
                width: 150,
            },
            // {
            //     dataIndex: 'personUuid',
            //     title: '人员信息',
            //     valueType: 'select',
            //     valueEnum: personUuid,
            //     rules: true,
            //     width: 200,
            //     hideInSearch: true,
            // },
            {
                dataIndex: 'deviceSerial',
                title: '设备编号',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'helmetType',
                title: '类型',
                valueType: 'select',
                valueEnum: BuiltInData.HelmetTypeList,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'personName',
                title: '人员信息',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            {
                dataIndex: 'mobile',
                title: '手机号码',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
            },
            { ...commonTableList.isEnabled, rules: true },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 240,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === '607e6ad4-3020-4ca5-9223-483ef35b09ae') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        <SelectButton
                            key="upload"
                            title="上传数据"
                            OptionsEvent={OptionsEvent}
                            data={{
                                actionRef,
                                options: centNameOptions,
                                label: '上传平台',
                                url: 'posBCCenterPushCenterHelmet',
                                uuid: record.uuid,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === '7748062f-1c5e-4ab2-9a9b-eb2ed40f6d0f') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
